package com.globalwave.common.appframe.simple
{
	import com.globalwave.common.Pagination;
	import com.globalwave.common.appframe.ModuleInf;
	import com.globalwave.common.appframe.ModuleLoader;
	import com.globalwave.common.appframe.SubFormInf;
	
	import flash.events.Event;
	
	import flexlib.mdi.containers.MDICanvas;
	import flexlib.mdi.containers.MDIWindow;
	import flexlib.mdi.events.MDIWindowEvent;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	public class SubForm extends MDIWindow implements SubFormInf
	{
		private var moduleLoader:ModuleLoader ;
		public var url:String ;
		
		public var module:ModuleInf ;
		
		public var mainForm:MainForm ;
		
		public function SubForm(mainForm:MainForm)
		{
			this.mainForm = mainForm;
			moduleLoader = new ModuleLoader(this) ; 
			this.addEventListener("initialize", thisOnInit) ;
		}
		
		
		private function thisOnInit(e:Event):void {	
			moduleLoader.load(url);
		}
		
		public function getButtons():ArrayCollection {
			/*
			if (buttons == null) {
				buttons = new ArrayCollection() ;
				buttons.addItem({
					icon:"@Embed('assets/img/3_closeButton.png')",
					label:"Add",
					click:"add"
				});
				buttons.addItem({
					icon:"@Embed('assets/img/3_closeButton.png')",
					label:"Edit",
					click:"edit"
				});
				buttons.addItem({
					icon:"@Embed('assets/img/3_closeButton.png')",
					label:"Delete",
					click:"delete"
				});
			}
			return buttons ;*/
			
			if (this.module == null) {
			    return null ;
			}
			
			return this.module.getButtons() ;
		}
		
	
		public function onButtonClick(button:Object):void {
			if (this.module != null) {
			    this.module.onButtonClick(button);
			}
		}
		
		public function setModule(module:ModuleInf):void{
			this.module = module;
		}
		
		public function loadMouldOnCompleted():void {
		    if (this == this.mainForm.currentWindow) {// 完成加载后，若当新窗口还是活动窗口，重新刷新界面
				this.dispatchEvent(new MDIWindowEvent(MDIWindowEvent.FOCUS_START, this));
			}
		}
		/*
		public function getPagination():Pagination {
		    return (this.parent as MDIMainForm).paginationBar;
		}*/
	}
}